package com.study.d3_annotation;

import org.junit.Test;

import java.lang.reflect.Method;
import java.util.Arrays;

//目标：注解的解析
public class AnnoTest3 {
  //测试方法：公开的、无参的、无返回值的
    @Test
    public void parseAnnoClass(){
        Class<Demo> demoClass = Demo.class;

        //1、判断类上面是否陈列了该注解
        if(demoClass.isAnnotationPresent(MyTest4.class)){
            //2、得到这个注解对象
            MyTest4 myt4 = demoClass.getDeclaredAnnotation(MyTest4.class);
            System.out.println(myt4.value());
            System.out.println(myt4.aaa());
            System.out.println(Arrays.toString(myt4.bbb()));
        }
    }

    @Test
    public void parseAnnoMethod() throws Exception{
        Class<Demo> demoClass = Demo.class;
        Method me = demoClass.getMethod("test1");

        //1、判断方法上面是否陈列了该注解
        if(me.isAnnotationPresent(MyTest4.class)){
            //2、得到这个注解对象
            MyTest4 myt4 = me.getDeclaredAnnotation(MyTest4.class);
            System.out.println(myt4.value());
            System.out.println(myt4.aaa());
            System.out.println(Arrays.toString(myt4.bbb()));
        }
    }
}

@MyTest4(value = "java",bbb={"sao","gou","658和"})
class Demo{
    @MyTest4(value = "色即是空",aaa=999,bbb={"心经","空即是色","哈哈"})
    public void test1(){

    }
}